package com.tec.security.controller;

import com.tec.security.utils.file.FileResult;
import com.tec.security.utils.file.FileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@Api(tags = "文件上传")
@RequestMapping("/upload/")
public class FileUploadController {
    private final FileUploadService fileUploadService;
    @Autowired
    public FileUploadController(FileUploadService fileUploadService) {
        this.fileUploadService = fileUploadService;
    }

    @ResponseBody
    @ApiOperation(value = "图片上传")
    @PostMapping("/images")
    public FileResult fileUpload(@RequestParam("files") MultipartFile files, HttpServletRequest request) throws IOException {
        return fileUploadService.fileUpload(files,request);
    }
}
